import 'dart:async';

import 'package:get/get.dart';
import 'package:situation/app/router/router_name.dart';
import 'package:situation/data/request/intell_request.dart';

import 'state.dart';

class IntellInfoTimelineController extends GetxController {
  final IntellInfoTimelineState state = IntellInfoTimelineState();

  final id = Get.arguments['id'];

  int current = 1;
  int size = 10;

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
    getData();
  }

  getData() async {
    var d = await IntellRequest.getIntellDetail(id);
    state.intellDetail = d['data'];

    var data = await IntellRequest.getTimeLineList(id, current, size);
    state.timeLine.addAll(data);
    state.timeLine = state.timeLine.toList();
  }

  FutureOr onLoad() async {
    current++;
    await getData();
  }

  FutureOr onRefresh() {
    current = 1;
    state.timeLine.clear();
    getData();
  }

  void toTimeLimeUpload() async {
    var s =await Get.toNamed(
      RouterName.intellInfoTimeLineUpload,
      arguments: {"id": id},
    );
    getData();
  }
}
